/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.shsc.dao.implementations;

import com.bionic.shsc.dao.interfaces.IProblemDAO;
import com.bionic.shsc.entities.ProblemData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ant
 */
public class MySQLProblem  extends QueryExecutor implements IProblemDAO{

    @Override
    public ArrayList<ProblemData> getProblemList(String aQuestionList) {
    ArrayList<ProblemData> problems = new   ArrayList<ProblemData>();
        String querySQL = "SELECT `problems`.`problem_id`,    `problems`.`question_id`,    `problems`.`problem_text` FROM `shsc`.`problems`\n" +
    "where `problems`.`question_id` in (%s)";
        try {
            PreparedStatement pstmt = query.getConnection().prepareStatement(querySQL);
            pstmt.setString(1, aQuestionList);
            ResultSet results = pstmt.executeQuery();
            while (results.next()) {
                ProblemData p = new ProblemData();
                p.setProblemID(results.getInt("problem_id"));
                p.setQuestionID(results.getInt("question_id"));
                p.setText(results.getString("problem_text"));
             problems.add(p);
            }
            return problems;
        } catch (SQLException ex) {
            Logger.getLogger(MySQLQuery.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
    
}
